/****************************************/
/* Leg.cpp			 					*/
/* Created on: Sep 4, 2011				*/
/* Copyright Playsoft 2011				*/
/* Released under GPL v2				*/
/****************************************/

#include "Leg.h"

//----------------------------------------------------------------------

BITMAP *Leg::legBitmap = 0x0;

//----------------------------------------------------------------------

Leg::Leg(float gravity) : locationY(-90.0f) , speedY(0.0f) , isHit(false)
{
	locationX = rand() % 700 + 50;
	this->gravity = gravity;
}

//----------------------------------------------------------------------

Leg::~Leg()
{

}

//----------------------------------------------------------------------

void Leg::init()
{
	legBitmap = load_bmp("data/stopa.bmp", default_palette );
}

//----------------------------------------------------------------------

void Leg::clear()
{
	destroy_bitmap(legBitmap);
}

//----------------------------------------------------------------------

void Leg::update(float growSpeed)
{
	if(!isHit)
	{
		speedY += gravity;
		locationY += speedY + growSpeed;

		if(locationY > 690)
			hit();
	}
}

//----------------------------------------------------------------------

void Leg::draw(BITMAP *buffer)
{
	masked_blit(legBitmap, buffer, 0, 0, (int)locationX, (int)locationY, 139, 126);
}

//----------------------------------------------------------------------

void Leg::hit()
{
	isHit = true;
	speedY = 0.0f;
}

//----------------------------------------------------------------------

bool Leg::getHit()
{
	return isHit;
}

//----------------------------------------------------------------------
